package pref.junx.flybird.activity.UpdataUserInfo;

import android.support.v7.widget.PopupMenu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import pref.junx.flybird.R;
import pref.junx.flybird.activity.main.NewMainActivity;
import pref.junx.flybird.base.BaseActicvitylhy;
import pref.junx.flybird.entity.User_idea;
import pref.junx.flybird.tools.JumpUtil;


/**
 * Created by 半生瓜 on 2017/8/7.
 */

public class UpdataUserInfoActvity extends BaseActicvitylhy<UpdataUserInfoPresenter, UpdataUserInfoModel> implements UpdataUserInfoConteact.View {
    TextView sex_tx;
    EditText nick,phone,email;
    LinearLayout sex;
    String uuf_sex;
    Button sure;
    private PopupMenu pop;
    @Override
    public int getLayoutId() {
return R.layout.updata_user_info_layout;    }

    @Override
    public void initview() {
        nick=(EditText)findViewById(R.id.uif_nick_et);
        phone=(EditText)findViewById(R.id.uif_phone);
        email=(EditText)findViewById(R.id.uif_email);
        sex=(LinearLayout)findViewById(R.id.uui_setting_sex);
        sure=(Button)findViewById(R.id.uif_sure_bt);
              sex_tx=(TextView)  findViewById(R.id.ufi_ui_sex);
        sex.setOnClickListener(this);
        sure.setOnClickListener(this);
        pop = new PopupMenu(this, sex_tx);
        pop.getMenuInflater().inflate(R.menu.manorwoman, pop.getMenu());
        pop.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                switch (item.getItemId())
                {
                    case R.id.man:
                        uuf_sex="男";
                        sex_tx.setText("男");
                        break;
                    case R.id.woman:
                        sex_tx.setText("女");
                        uuf_sex="女";
                        break;
                }
                return false;
            }
        });
    }

    @Override
    public void processClick(View view) {
       switch (view.getId()){
           case R.id.uui_setting_sex:
               pop.show();
           ;break;
           case R.id.uif_sure_bt:
               User_idea user=new User_idea();
               user.setUser_id(Integer.valueOf(spTools.getString("user_id")));
               user.setPhone(phone.getText().toString().trim());
               user.setEmail(email.getText().toString().trim());
               user.setSex(sex_tx.getText().toString().trim());
               user.setUser_nick(nick.getText().toString().trim());
               presenter.updata(user);
       }
    }


    @Override
    public void init() {
        uuf_sex=spTools.getString("sex");
        nick.setText(spTools.getString("user_nick"));
        email.setText(spTools.getString("email"));
        sex_tx.setText(spTools.getString("sex"));
        phone.setText(spTools.getString("phone"));
    }





    @Override
    public void success() {

    }

    @Override
    public void result(String a) {

    }

    @Override
    public void Success() {
        t.show_l("修改成功");
        NewMainActivity.newMainActivity.finish();
        JumpUtil.to(c,NewMainActivity.class);
        finish();
    }

    @Override
    public void Fail() {
        t.show_l("修改失败");

    }
}


